namespace hjc {

	export class Notification implements IPoolable {
		private $type: string;
		private $data?: any;
		private $source?: any;
		public init(type: string, data?: any, source?: any): Notification {
			this.$type = type;
			this.$data = data;
			this.$source = source;
			return this;
		}
		public get type(): string { return this.$type; }
		public get data(): any { return this.$data; }
		public get source(): any { return this.$source; }

		//获得数据(指定key值)
		public key(key: string): any { return !!this.$data ? this.$data[key] : null; }

		//若(通知)携带数据,则执行
		public withData(next: Function): void { if (!!this.$data && isFunc(next)) next(this.$data); }

		//若(通知)携带key值数据,则执行
		public keyExist(key: string, next: Function): void { if (!!this.$data && this.$data[key] !== undefined && isFunc(next)) next(this.$data[key]); }

		//若(通知)携带key值为真,则执行
		public keyTrue(key: string, next: Function): void { if (!!this.$data && this.$data[key] === true && isFunc(next)) next(this.$data); }

		//若(通知)携带数据,则按照key值分流执行
		public divByKey(key: string, trueNext?: Function, falseNext?: Function): void {
			if (!!this.$data) {
				if (this.$data[key] && isFunc(trueNext)) trueNext(this.$data);
				else if (isFunc(falseNext)) falseNext(this.$data);
			}
		}
	}
}

